package com.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.api.common.jwt.TokenIgnore;
import com.api.common.reqres.Request;
import com.api.common.reqres.Response;
import com.api.model.request.FrontLoginRequest;
import com.api.model.request.FrontUserUpdateRequest;
import com.api.model.request.NullRequest;
import com.api.model.request.OpenidRequest;
import com.api.model.request.RegisteredRequest;
import com.api.model.request.SmsCodeRequest;
import com.api.model.response.FrontLoginResponse;
import com.api.model.response.NullResponse;
import com.api.model.response.OpenidResponse;
import com.api.model.response.RegisteredResponse;
import com.api.service.FrontUserService;

import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 前端用户相关接口
 * </p>
 *
 * @author cfp
 * @since 2019-10-14
 */
@RestController
public class FrontUserController {

	@Autowired
	private FrontUserService frontUserService;

	@TokenIgnore
	@ApiOperation(notes = "注册", value = "注册")
	@PostMapping(value = "/registered.do")
	public Response<RegisteredResponse> registered(@RequestBody Request<RegisteredRequest> request) throws Exception {
		return frontUserService.registered(request);
	}

	@TokenIgnore
	@ApiOperation(notes = "获取验证码", value = "获取验证码")
	@PostMapping(value = "/smsCode.do")
	public Response<NullResponse> smsCode(@RequestBody Request<SmsCodeRequest> request) throws Exception {
		return frontUserService.smsCode(request);
	}

	@TokenIgnore
	@ApiOperation(notes = "前端用户登陆", value = "前端用户登陆")
	@PostMapping(value = "/frontLogin.do")
	public Response<FrontLoginResponse> frontLogin(@RequestBody Request<FrontLoginRequest> request) throws Exception {
		return frontUserService.frontLogin(request);
	}

	@ApiOperation(notes = "前端用户信息", value = "前端用户信息")
	@PostMapping(value = "/frontUser.do")
	public Response<NullResponse> frontUser(@RequestBody Request<NullRequest> request) throws Exception {
		return frontUserService.frontUser(request);
	}

	@TokenIgnore
	@ApiOperation(notes = "前端用户信息更新", value = "前端用户信息")
	@PostMapping(value = "/frontUserUpdate.do")
	public Response<NullResponse> frontUserUpdate(@RequestBody Request<FrontUserUpdateRequest> request)
			throws Exception {
		return frontUserService.frontUserUpdate(request);
	}

	@TokenIgnore
	@ApiOperation(notes = "获取openid", value = "获取openid")
	@PostMapping(value = "/openid.do")
	public Response<OpenidResponse> openid(@RequestBody Request<OpenidRequest> request) throws Exception {
		return frontUserService.openid(request);
	}
}
